//
//  CenterFirstCell.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/9/28.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "CenterFirstCell.h"
#import "UIButton+LZCategory.h"


@implementation CenterFirstCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createHeraderView];
    }
    return self;
}



-(void)createHeraderView{
    UIImageView *headerImageView = [[UIImageView alloc] init];
    headerImageView.userInteractionEnabled = YES;
    [self.contentView addSubview:headerImageView];
//    headerImageView.image = [UIImage imageNamed:@"2.jpg"];
    [headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.contentView);
        make.height.mas_equalTo(scaleTopAndBottom(190));
    }];
    [self loopViewDelegateAndAddToFatherView:headerImageView];
    UIView *bottomView = [[UIView alloc] init];
    [self.contentView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headerImageView.mas_bottom);
        make.left.right.bottom.equalTo(self.contentView);
    }];
    UIImageView *lineImageView = [[UIImageView alloc] init];
    lineImageView.image = [UIImage imageNamed:@"catasousuo"];
    [bottomView addSubview:lineImageView];
    [lineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
      make.top.equalTo(bottomView.mas_top).offset(scaleTopAndBottom(20));
        make.height.mas_equalTo(scaleTopAndBottom(13));
        make.centerX.equalTo(bottomView);
        make.width.mas_equalTo(scaleLeftAndRight(251));
    }];
    
    UIImageView *activityBtn = [[UIImageView alloc] init];
    
    activityBtn.image = [UIImage imageNamed:@"centerpageactivity"];
//    [activityBtn setBackgroundImage:[UIImage imageNamed:@"centerpageactivity"] forState:UIControlStateNormal];
    [bottomView addSubview:activityBtn];
    UIImageView *comeptionBtn = [[UIImageView alloc] init];
    comeptionBtn.image = [UIImage imageNamed:@"centerpageReword"];
    [bottomView addSubview:comeptionBtn];
    UIImageView *insitituBtn = [[UIImageView alloc] init];;
    insitituBtn.image = [UIImage imageNamed:@"centerpageacompetition"];
    [bottomView addSubview:insitituBtn];
    [activityBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineImageView.mas_bottom).offset(scaleTopAndBottom(22));
        make.left.equalTo(bottomView.mas_left).offset(scaleLeftAndRight(30));
        make.height.mas_equalTo(scaleTopAndBottom(73));
        make.width.mas_equalTo(scaleLeftAndRight(78));
    }];
    [comeptionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineImageView.mas_bottom).offset(scaleTopAndBottom(22));
        make.centerX.equalTo(bottomView.mas_centerX);
        make.height.mas_equalTo(scaleTopAndBottom(73));
        make.width.mas_equalTo(scaleLeftAndRight(80));
    }];
    [insitituBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineImageView.mas_bottom).offset(scaleTopAndBottom(22));
        make.height.mas_equalTo(scaleTopAndBottom(73));
        make.right.equalTo(bottomView.mas_right).offset(scaleLeftAndRight(-30));
        make.width.mas_equalTo(scaleLeftAndRight(73));
    }];
    activityBtn.userInteractionEnabled = YES;
    comeptionBtn.userInteractionEnabled = YES;
    insitituBtn.userInteractionEnabled = YES;
    activityBtn.tag = 1001;
    comeptionBtn.tag = 1002;
    insitituBtn.tag = 1003;
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pageAndTransform:)];
    [activityBtn addGestureRecognizer:tap1];
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pageAndTransform:)];
    [comeptionBtn addGestureRecognizer:tap2];
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pageAndTransform:)];
    [insitituBtn addGestureRecognizer:tap3];
    
    UILabel *activiLabel = [[UILabel alloc] init];
    activiLabel.text = @"活动推荐";
    activiLabel.textAlignment = NSTextAlignmentCenter;
    activiLabel.font = [UIFont systemFontOfSize:13];
    activiLabel.textColor = COLOR_HEX(0x121212);
    [bottomView addSubview:activiLabel];
    [activiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(activityBtn.mas_bottom).offset(7);
        make.left.equalTo(bottomView.mas_left).offset(scaleLeftAndRight(30));
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(scaleLeftAndRight(75));
    }];
    UILabel *competionLabel = [[UILabel alloc] init];
    competionLabel.text = @"赛事回顾";
    competionLabel.textAlignment = NSTextAlignmentCenter;
    competionLabel.font = [UIFont systemFontOfSize:13];
    competionLabel.textColor = COLOR_HEX(0x121212);
    [bottomView addSubview:competionLabel];
    [competionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(comeptionBtn.mas_bottom).offset(7);
        make.centerX.mas_equalTo(bottomView.mas_centerX);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(scaleLeftAndRight(75));
    }];
    UILabel *insitituLabel = [[UILabel alloc] init];
    insitituLabel.text = @"机构推荐";
    insitituLabel.textAlignment = NSTextAlignmentCenter;
    insitituLabel.font = [UIFont systemFontOfSize:13];
    insitituLabel.textColor = COLOR_HEX(0x121212);
    [bottomView addSubview:insitituLabel];
    [insitituLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(insitituBtn.mas_bottom).offset(7);
//        make.left.equalTo(competionLabel.mas_right).offset(30);
        make.right.equalTo(bottomView.mas_right).offset(scaleLeftAndRight(-30));
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(scaleLeftAndRight(75));
    }];
}
-(void)pageAndTransform:(UITapGestureRecognizer *)tap{
    UIView *view = tap.view;
    switch (view.tag) {
        case 1001:
            self.pageTransformBlockOne();
            break;
        case 1002:
            self.pageTransformBlockTwo();
            break;
        case 1003:
            self.pageTransformBlockThree();
            break;
        default:
            break;
    }
}


#pragma mark -图片轮播
- (void)loopViewDelegateAndAddToFatherView:(UIView *)faterView{
    NSArray *array = @[@"banner(1).jpg",@"元旦狗.jpg"];
    // 类方法
    YYInfiniteLoopView *loopView = [YYInfiniteLoopView
                                    infiniteLoopViewWithImageUrls:array
                                    titles:nil
                                    didSelectedImage:^(NSInteger index) {
                                        NSLog(@"%zd",index);
                                    }];
    // 设置代理
    loopView.delegate = self;
    loopView.timeInterval = 5;
    loopView.currentPageIndicatorColor = [UIColor yellowColor];
    loopView.pagePosition = InfiniteLoopViewPagePositionCenter;
    loopView.frame = CGRectMake(0, 0, WIDTH, scaleTopAndBottom(190));
    [faterView addSubview:loopView];
}
#pragma mark - YYInfiniteLoopViewDelegate
- (void)infiniteLoopView:(YYInfiniteLoopView *)infiniteLoopView
        didSelectedImage:(NSInteger)selectedImageIndex {
    [self didSelectedImageWithIndex:selectedImageIndex];
}
- (void)didSelectedImageWithIndex:(NSInteger)index {
    NSLog(@"点击了%ld",index);
}
#pragma mark 实现搜索条背景透明化

- (UIImage*) GetImageWithColor:(UIColor*)color andHeight:(CGFloat)height{
    
    CGRect r= CGRectMake(0.0f, 0.0f, 1.0f, height);
    
    UIGraphicsBeginImageContext(r.size);
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    
    CGContextFillRect(context, r);
    
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return img;
    
}
@end
